<template>
  <div>
    <div>
        <span>差距与改进&nbsp;&nbsp;&nbsp;&nbsp;</span>
        <span style="color: #888" v-if="model.submitdate">{{ model.username }}{{ formatDate(model.submitdate) }}填写</span>
    </div>
    <el-form class="tl-form taskForm" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit" style="margin-right: 10px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="差距分析" prop="gapanalysis" :rules="rules.validateRequire">
            <el-input v-model="model.gapanalysis" type="textarea" :autosize="{ minRows:1, maxRows:3 }" maxlength="1000"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="改进计划" prop="managerplan" :rules="rules.validateRequire">
            <el-input v-model="model.managerplan" type="textarea" :autosize="{ minRows:1, maxRows:3 }" maxlength="1000"> </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="float: right;margin-right: 10px">
      <el-button icon='el-icon-delete' type="primary" @click="deleteFeedbackList" :loading="saveLoading" v-if="canDelete">删除</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit"> <svg-icon icon-class="save" />保存 </el-button>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
import { formatDate } from '@tapui/utils/date'
import { validateNull } from '@tapui/utils/validate'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  props: {
    render: {
      type: String,
      default: 'el-dialog'
    },
    newValue: {
      type: Object,
      default: () => {}
    },
    canEdit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      moduleTitle: '差距与改进',
      urlPrefix: '/mpm/projectTaskFeedback/',
      url: {
        // 额外的url
      },
      projectinfo: {}
    }
  },
  computed: {
    canDelete() {
      return validateNull(this.model.id)
    }
  },
  watch: {
      newValue: {
        handler(value, oldvalue) {
          this.model = value
          if (!this.model.hasOwnProperty('id')) {
            this.isAdd = true
            this.disableEditSubmit = false
          } else if (!this.canEdit) {
            this.isAdd = false
            this.disableEditSubmit = true
          } else {
            this.isAdd = false
            this.disableEditSubmit = false
          }
        },
        immediate: true,
        deep: true
      }
    // id: {
    //   immediate: true,
    //   handler(value, oldvalue) {
    //     debugger
    //     if (value && value > 0) {
    //       this.open()
    //     } else if (value === 0) {
    //         this.isAdd = true
    //         this.disableEditSubmit = false
    //         this.model = {}
    //     }
    //   }
    // }
  },
  methods: {
    assignDefaultValue() {
      if (this.isAdd) {
        this.$set(this.model, 'applyorgcode', this.org.code)
        this.$set(this.model, 'applyorgname', this.org.name)
        this.$set(this.model, 'applydeptcode', this.dept.code)
        this.$set(this.model, 'applydeptname', this.dept.fullname)
        this.$set(this.model, 'applyusercode', this.user.code)
        this.$set(this.model, 'applyusername', this.user.name)
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
        this.$set(this.model, 'deptcode', this.dept.code)
        this.$set(this.model, 'orgcode', this.org.code)
        this.$set(this.model, 'feedbackdate', new Date())
        this.$set(this.model, 'taskid', this.taskInfo.id)
        this.$set(this.model, 'taskname', this.taskInfo.taskname)
        this.$set(this.model, 'projectcode', this.taskInfo.projectcode)
        this.$set(this.model, 'istaskfeedback', '0')
        this.$set(this.model, 'state', 9)
        this.$set(this.model, 'submitdate', new Date())
      }
    },
    formatDate(date) {
      return validateNull(date) ? '' : '于' + formatDate(new Date(date ? date.toString().replace(/\-/g, "/") : date), 'yyyy-MM-dd HH:mm')
    },
    // 当点击删除按钮时，传递事件，删除feedbackList中新增内容
    deleteFeedbackList() {
      this.$emit('deleteList')
    }
  }
}
</script>

<style lang="scss" scoped>
.taskForm {
  margin-top: 15px;
  margin-left: -50px;
  .el-row {
    margin-bottom: 2px;
  }
}
</style>
